package leetcode.code1769;

import leetcode.IDebug;


//执行用时：2 ms, 在所有 Java 提交中击败了99.61%的用户
//
//内存消耗：42 MB, 在所有 Java 提交中击败了5.06%的用户
//
//通过测试用例：95 / 95
public class Solution implements IDebug {

//	输入：boxes = "001011"
//	输出：[11,8,5,4,3,4]
	public int[] minOperations(String boxes) {
		char[] bxs = boxes.toCharArray();
		int len = boxes.length();
		int[] l = new int[len];
		int[] r = new int[len];
		int one = 0;
		for (int i = 0; i < len; i++) {
			l[i] = one;
			one += bxs[i] == '1' ? 1 : 0;
		}
		one = 0;
		int sum = 0;
		for (int i = len - 1; i >= 0; i--) {
			if (bxs[i] == '1') {
				one++;
				sum += i;
			}
			r[i] = one;
		}
		int[] ans = new int[len];
		ans[0] = sum;
		for (int i = 1; i < len; i++) {
			ans[i] = ans[i - 1] - r[i] + l[i];
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
